@extends('Admin.layouts.common')

@section('content')
    <div class="container myContainer">

        @if(count($errors))
            <div class="alert alert-danger">
                <ul>
                    @foreach($errors->all() as $err)
                        <li>{{ $err }}</li>
                    @endforeach
                </ul>
            </div>
        @endif

        <form method="post">
            {{ csrf_field() }}
            <div class="form-group required">
                <label class="control-label">用户名</label>
                <input name="name" type="text" class="form-control" value="">
            </div>
            <div class="form-group required">
                <label class="control-label">用户密码</label>
                <input name="passwd" type="text" class="form-control" value="">
            </div>
            <div class="form-group required">
                <label class="control-label">用户密码确认</label>
                <input name="repasswd" type="text" class="form-control" value="">
            </div>
            <div class="form-group required">
                <label class="control-label">选择分组</label>
                <select name="group" class="form-control">
                    <option value="">请选择分组</option>
                    @foreach($group as $k=>$v)
                        <option value="{{$v->id}}" {{ old('group')==$k ? 'selected' : '' }}>{{$v->group_name}}</option>
                    @endforeach
                </select>
            </div>
            <div class="form-group required">
                <label class="control-label">权限设置 <button type="button" onclick="$('input').iCheck('check');">全选</button> <button type="button" onclick="$('input').iCheck('toggle');">反选</button></label>
                @foreach($admin_option_list as $root_menu => $r )
                    <h5 class="rights_title">{{ $root_menu }}：<button type="button" onclick="$('.{{$root_menu}}').find('input').iCheck('check');">全选</button> <button type="button" onclick="$('.{{$root_menu}}').find('input').iCheck('toggle');">反选</button></h5>
                    <div class="{{$root_menu}}">
                    @foreach($r as $rights => $menu)
                        <label class="rights_checkbox">
                            {{ $menu }}
                            <input type="checkbox" name="rights[]" value="{{ $rights }}">
                        </label>
                    @endforeach
                    </div>
                @endforeach
            </div>
            <div class="form-group">
                <button class="btn btn-primary btn-block" type="submit">新增</button>
            </div>
        </form>
    </div>
@endsection

@section('foot')
<link href="{{ asset('libs/select2/select2.min.css') }}" rel="stylesheet">
<script src="{{ asset('libs/select2/select2.min.js') }}"></script>
<script src="{{ asset('libs/select2/zh-CN.js') }}"></script>
<script>
    $("#uid").select2({
        language: "zh-CN",
        ajax:{
            url: "/Users/ajax_select2_user",
            dataType: 'json',
            delay: 600,
            method: 'POST',
            data: function (params) {
                return {
                    name: params.term,
                };
            },
            processResults: function (data, params) {
                return {
                    results: data.data,
                };
            },
            cache: true
        },
        placeholder:'请输入手机号码或用户名',
        allowClear: true,
        escapeMarkup: function (markup) { return markup; },
        minimumInputLength: 8,
        templateResult: function(repo){ return repo.name; },
        templateSelection: function(repo){ 
            if(repo.id === ""){
                return repo.text
            }else{
                if(repo.selected == true){
                    return repo.text
                }
                return repo.name
            }
             
        } 
    });
</script>
@endsection